package Algorithm;

public class ReplaceBlank_02 {
    public static String replaceBlank(String iniString){
        int count=iniString.length();
        for(int i=0;i<iniString.length();i++){
            if(iniString.charAt(i)==' '){
                count+=2; //计算新字符串长度
            }
        }
        char[] helper=new char[count];
        int p1=iniString.length()-1;
        int p2=count-1;
        for(int i=p1;i>=0;i--){
            if(iniString.charAt(i)==' '){
                helper[p2--]='0';
                helper[p2--]='2';
                helper[p2--]='%';
            }else{
                helper[p2--]=iniString.charAt(i);
            }
        }
        return new String(helper);
    }

    public static void main(String[] args) {
        System.out.println(replaceBlank("Mr John Smith"));
    }
}
